package com.bkgy.controller.tbcalflatness.service.impl;

import com.bkgy.controller.tbcalflatness.dao.TbCal1630FlatnessDao;
import com.bkgy.controller.tbcalflatness.entity.TbCal1630Flatness;
import com.bkgy.controller.tbcalflatness.entity.TbCal1630FlatnessRequest;
import com.bkgy.controller.tbcalflatness.service.TbCal1630FlatnessPdiService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;


/**
 * AI轧制力/AI工作辊服务实现类
 */
@Service
public class TbCal1630FlatnessPdiServiceImpl implements TbCal1630FlatnessPdiService {
    @Autowired
    private TbCal1630FlatnessDao tbCal1630FlatnessDao;

    @Override
    public ResultData getTbCal1630Flatness(TbCal1630FlatnessRequest request) {
        TbCal1630FlatnessRequest bean = new TbCal1630FlatnessRequest();
        try {
            TbCal1630Flatness tbCal1630Flatness  = tbCal1630FlatnessDao.getTbCal1630Flatness(request);
            if(tbCal1630Flatness != null) {
                bean.setWorkRollBendComp(tbCal1630Flatness.getWorkRollBendComp());
                bean.setEntid(tbCal1630Flatness.getEntid());
                bean.setIfSearch(tbCal1630Flatness.getIfSearch());
                bean.setIfSearchSame(tbCal1630Flatness.getIfSearchSame());
                bean.setSteelgrade(tbCal1630Flatness.getSteelgrade());
                bean.setInMatThick(tbCal1630Flatness.getInMatThk());
                bean.setInMatWidth(tbCal1630Flatness.getInMatWidth());
                bean.setImrShiftAdv(tbCal1630Flatness.getImrShiftAdv());
                bean.setIsLargeRollDiameter(tbCal1630Flatness.getIsLargeRollDiameter());
                bean.setIsElongMode(tbCal1630Flatness.getIsElongMode());

                if (tbCal1630Flatness.getIfSearchSame() == 1) {
                    bean.setAiRollForce(tbCal1630Flatness.getRollingForceSame());
                    bean.setAiWorkingRoll(tbCal1630Flatness.getWorkRollBendSame());
                    bean.setLowSpeedIntermediateRollBend(tbCal1630Flatness.getInterMediateRollBendSame());
                    bean.setConfidence("98%");
                } else {
                    if (tbCal1630Flatness.getIfSearch() == 0) {
                        bean.setAiRollForce(tbCal1630Flatness.getRollingForceCal());
                        bean.setAiWorkingRoll(BigDecimal.ZERO);
                        bean.setLowSpeedIntermediateRollBend(BigDecimal.ZERO);
                        bean.setConfidence("50%");
                        return ResultData.ResultDataSuccess(bean);
                    }

                    // 剩余情况默认处理 ifSearch == 1
                    bean.setAiWorkingRoll(tbCal1630Flatness.getLowSpeedWorkRollBend());
                    bean.setLowSpeedIntermediateRollBend(tbCal1630Flatness.getLowSpeedIntermediateRollBend());
                    BigDecimal force = tbCal1630Flatness.getLerningAcount() >= 5
                            ? tbCal1630Flatness.getLowSpeedRollingForce()
                            : tbCal1630Flatness.getLowSpeedRollingForceCal();
                    if (tbCal1630Flatness.getLerningAcount() >= 5) {
                        bean.setConfidence("80%");
                    } else {
                        bean.setConfidence("60%");
                    }
                    bean.setAiRollForce(force);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("获取失败" + e.getMessage(), null);
        }
        return ResultData.ResultDataSuccess(bean);
    }

}
